home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’92 / PatchWorks Kit / <PatchWorks++> / PatchGlue.a < prev    next >
Text File  |  1992-04-27  |  2KB  |  88 lines

  1. ;
  2. ;    PatchGlue.a
  3. ;
  4. ;    Universal patch glue for PatchWorks. MPW Assembler version.
  5. ;
  6. ;    by Patrick C. Beard.
  7. ;
  8. ;
  9.     INCLUDE    'Traps.a'
  10.     INCLUDE 'Patch.a'                                ; bring in record definitions.
  11. ;
  12. FP        EQU        a3
  13. ;
  14. ;    void* NewPatchGlue(Patch* this);
  15. ;
  16. ;    Creates an instance of patch glue. Saves the pointer to the patch object
  17. ;    passed in pc-relative.
  18. ;
  19. NewPatchGlue    PROC    EXPORT
  20.         WITH    Patch                                ; use the Patch object.
  21.         bra.s    @measure
  22. @agent    subq    #4, sp
  23.         link    FP, #0
  24.         movem.l    d0-d2/a0-a1/a4, -(sp)
  25.         move.l    @patch, a0
  26.         move.l    itsOld(a0), 4(FP)                    ; put old trap address on stack.
  27.         move.b    itsState(a0), d0                    ; see if patch is on.
  28.         beq.s    @restore
  29.         move.l    itsBehavior(a0), d0                    ; see if a behaviour is there.
  30. ;;        beq.s    @restore
  31.         
  32.         clr.l    -(sp)                                ; save room for stack adjustment.
  33.         move.l    a0, -(sp)                            ; pass patch instance.
  34.         
  35.         move.l    (a5), a1                            ; caller's current port.
  36.         move.l    (a1), -(sp)
  37.         move.l    a5, -(sp)                            ; save caller's a5
  38.         
  39.         move.l    itsGlobals(a0), GLOBALS                ; set up the patch's globals.
  40.         move.l    d0, a0
  41.         jsr        (a0)                                ; call the behavior.
  42.         
  43.         move.l    (sp), a5                            ; restore caller's a5.
  44.  
  45.         add.l    #12, sp                                ; remove stuff we pushed.
  46.         move.l    (sp)+, d0
  47.         beq.s    @restore
  48.         
  49.         ; we're heading off the patch, return to caller.
  50.         move.l    d0, FP
  51.         move.l    32(sp), -(FP)                        ; get caller's return address.
  52.         move.l    24(sp), -(FP)                        ; get old value of FP so unlk works.
  53.  
  54. @restore
  55.         movem.l    (sp)+, d0-d2/a0-a1/a4
  56.         unlk    FP
  57.         rts
  58.  
  59. @macsbug        
  60.         dc.b    $80 + $A, 'PatchAgent'                ; macsbug symbol.
  61.  
  62. @patch
  63.         dc.l    0                                    ; place to store pointer to instance.
  64.  
  65. @measure
  66.         lea        @patch, a1
  67.         move.l    4(sp), (a1)+                        ; store the patch instance pc-relative.
  68.         lea        @agent, a0
  69.         sub.l    a0, a1                                ; compute the size of the glue.
  70.         move.l    a1, d1
  71.         move.l    d1, d0                                ; size of glue in d1.
  72.         _NewPtr                                        ; allocate a block to hold glue.
  73.         
  74.         move.l    a0, d0                                ; make sure storage allocated properly.
  75.         beq.s    @end
  76.         
  77.         move.l    a0, a1                                ; copy the glue to new block.
  78.         move.l    d1, d0
  79.         lea        @agent, a0
  80.         _BlockMove
  81.         
  82.         move.l    a1, d0                                ; return pointer to glue.
  83. @end
  84.         rts
  85.  
  86.     ENDP
  87. ;
  88.